<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>跑马灯效果</title>
    <script src="./lib/vue-2.4.0.js"></script>
</head>
<body>
    <div id="app">
        <input type="button" value="GO" @click="letgo">
        <input type="button" value="STOP" @click="stopit">
        <h4>{{ msg }}</h4>
    </div>


    <script>
    var vm = new Vue({
        el: '#app',
        data: {
            msg: 'There is a sentence here which is shown.',
            intervalId: null
        },

        methods: {
            letgo(){
                if (this.intervalId != null) return;

                this.intervalId = setInterval(() => {
                    var start = this.msg.substring(0, 1)
                    var end = this.msg.substring(1)

                    this.msg = end + start
                }, 400)
            },

            stopit(){
                clearInterval(this.intervalId)
                this.intervalId = null
            }
        }
    })
    
    </script>
</body>
</html>